package org.lim.shared.websocket.service.strategy;

import org.lim.shared.websocket.model.enums.PictureEditMessageTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
public class PictureEditMessageStrategyFactory {
    
    @Resource(name = "enterEditStrategy")
    private PictureEditMessageStrategy enterEditStrategy;
    
    @Resource(name = "editActionStrategy")
    private PictureEditMessageStrategy editActionStrategy;
    
    @Resource(name = "exitEditStrategy")
    private PictureEditMessageStrategy exitEditStrategy;
    
    private final Map<PictureEditMessageTypeEnum, PictureEditMessageStrategy> strategies = new HashMap<>();
    
    @PostConstruct
    public void init() {
        strategies.put(PictureEditMessageTypeEnum.ENTER_EDIT, enterEditStrategy);
        strategies.put(PictureEditMessageTypeEnum.EDIT_ACTION, editActionStrategy);
        strategies.put(PictureEditMessageTypeEnum.EXIT_EDIT, exitEditStrategy);
    }
    
    /**
     * 获取对应的策略实现
     * @param messageType 消息类型
     * @return 策略实现
     */
    public PictureEditMessageStrategy getStrategy(PictureEditMessageTypeEnum messageType) {
        return strategies.get(messageType);
    }
}